home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / echsys10.zip / ENVSYS.ASM < prev    next >
Assembly Source File  |  1989-09-25  |  25KB  |  600 lines

  1. ; EnvSys  : put current system data (drive, dir, time, date etc)
  2. ;           into an environment variable named first on the command line
  3. ;
  4. ; Version 1.0
  5. ;
  6. ; Free Software by TapirSoft Gisbert W.Selke, Sept 1989
  7. ;
  8. ; The environment setting stuff is
  9. ;   Copyright 1987, A. B. Krueger GPW MI 48236
  10. ;   All rights reserved. Contact "ARNY KRUEGER"
  11. ;   at the EXEC-PC BBS (414-964-5160) for permission
  12. ;   to use commercially.
  13. ;
  14. ; Otherwise, this programme may be used and copied any way you wish, but don't
  15. ; sell it. Give credit where credit is due, please. - The copyright remains
  16. ; with me and Arny; I do not guarantee proper operation of this utility; the
  17. ; whole risk of use lies with the user.
  18. ;
  19. ; Usage:   envsys <varname> <string>
  20. ;          String is put into an environment variable named varname;
  21. ;          two-char sequences introduced by '^' are replaced as indicated
  22. ;          at 'Usage' below.
  23. ;
  24. ; TASM     envsys                   or        MASM   envsys
  25. ; TLINK /t envsys                             LINK   envsys
  26. ;                                             EXEBIN envsys.exe envsys.com
  27.  
  28. BackSpace       Equ     08h
  29. LineFeed        Equ     0Ah
  30. Return          Equ     0Dh
  31. CtrlZ           Equ     1Ah
  32.  
  33.  
  34.  
  35. StuffChar       Macro   Chr                     ; macro to put a character
  36.                 Push    ax
  37.                 Mov     al, Chr                 ; into the env string
  38.                 Call    StuffIt
  39.                 Pop     ax
  40.                 Endm
  41.  
  42. Jmps            Macro   Label                   ; Jump short
  43.                 Jmp short Label
  44.                 Endm
  45.  
  46.  
  47. cseg            Segment para public
  48.  
  49.                 Extrn   env_set:near,DirString:byte,TimeBuf:byte,DateBuf:byte
  50.                 Extrn   OutLine:byte,OurStack:byte,ProgEnd:byte
  51.  
  52.  
  53.                 Org 0080h
  54. Parameter       Db      ?
  55.  
  56.                 Org 100h
  57.                 Assume cs:cseg, ds:cseg, es:cseg, ss:cseg
  58.  
  59. Start:          Jmp     Begin
  60.  
  61.                 db      'SPECIAL='
  62. Special         db      '^'
  63.  
  64.                 db      Return
  65. Copyright       db      'EnvSys 1.0 - Free software by TapirSoft'
  66.                 db      ' Gisbert W.Selke, Sept 89', Return, LineFeed
  67.                 db      'Parts copyright 1987, A. B. Krueger GPW MI 48236. '
  68.                 db      Return, LineFeed
  69.                 db      'Use at your own risk.$', BackSpace, ' '
  70.                 db      Return, LineFeed, CtrlZ
  71.  
  72. Usage1          db      Return, LineFeed, LineFeed
  73.                 db      'Usage: envsys <varname> <string>', Return, LineFeed
  74.                 db      'The string is put into the named environment '
  75.                 db      'variable', Return, LineFeed
  76.                 db      'with "$'
  77. Usage2          db      '@" replaced as indicated by @:', Return, LineFeed
  78.                 db      ': drive; \ directory; F free disk space; '
  79.                 db      'T total disk space; R free RAM;', Return, LineFeed
  80.                 db      'r RAM size; l #drives; f #floppies; P #printers; '
  81.                 db      'S #serial ports;', Return, Linefeed
  82.                 db      '7 coprocessor? L LPT1 status; V video mode; '
  83.                 db      'w screen width; t type of PC;', Return, LineFeed
  84.                 db      'v DOS version; b BIOS version; i "<" symbol; '
  85.                 db      'o ">" symbol; p "|" symbol; ', Return, LineFeed
  86.                 db      'O switch char; A author''s note; '
  87.                 db      'x char given by next 2 hex digits;', Return, LineFeed
  88.                 db      'K key typed by user; C country code; $'
  89. Usage3          db      ' currency string;', Return, LineFeed
  90.                 db      'k 1000s separator; 1 decimal separator; '
  91.                 db      '/ date separator; - time separator;'
  92.                 db      Return, LineFeed
  93.                 db      'D day; M month; Y year; W weekday; h hour; m minute; '
  94.                 db      's second; c centisecond.'
  95.                 db      Return, LineFeed, Return, LineFeed, '$'
  96.  
  97. RetVal          db      0
  98.  
  99. ModelString     db      '??80AP30??ATJRXTPC'
  100. ModelStrLen     Label   Byte
  101.  
  102. CmdLetters      db      'csmhWYMD-/1k$CpoiKxAObvtwVL7SPflRrTF\:';command letters
  103. EndCmdLetters   Label   Word
  104.  
  105. ; **NOTE**: order of CmdLetters and Dispatch is reversed w.r.t. each other!
  106.  
  107. Dispatch        dw      Drive, Directory, FreeSpace, TotalSpace, MemSize
  108.                 dw      FreeMem, LogicDrives, Floppies, Printers
  109.                 dw      CommPorts, Coproc, LptStat, VideoMode, VideoWidth
  110.                 dw      SysModel, DosVersion, BiosVersion, SwitchChar, Author
  111.                 dw      Hexnumber, KeyBoard
  112.                 dw      StdInSymbol, StdOutSymbol, PipeSymbol, CountryInfo
  113.                 dw      Currency, Thousands, Decimal, DateSep, TimeSep
  114.                 dw      Day, Month, Year, WeekDay
  115.                 dw      Hour, Minute, Second, CentiSecond
  116.  
  117.  
  118. Begin:          Mov     sp, Offset OurStack     ; point to our own stack
  119.  
  120.                 Mov     ah, 2Ch                 ; get current time right now
  121.                 Int     21h
  122.                 Mov     [TimeBuf],   ch         ; stow away
  123.                 Mov     [TimeBuf+1], cl
  124.                 Mov     [TimeBuf+2], dh
  125.                 Mov     [TimeBuf+3], dl
  126.                 Mov     ah, 2Ah                 ; get current date
  127.                 Int     21h
  128.                 Sub     cx, 1900                ; remove centuries
  129.                 Mov     word ptr [DateBuf], cx  ; stow away
  130.                 Mov     [DateBuf+2], dh
  131.                 Mov     [DateBuf+3], dl
  132.                 Mov     [DateBuf+4], al
  133.  
  134.                 Mov     si, 1+offset Parameter  ; command line string
  135.                 Xor     al, al
  136.                 Mov     [OutLine], al           ; init environment line
  137.  
  138. FindName:       Lodsb                           ; find first parameter,
  139.                 Cmp     al, Return              ; i.e., name of env variable
  140.                 Je      ShowUsage
  141.                 Cmp     al, ' '
  142.                 Je      FindName
  143.                 Cmp     al, 09h
  144.                 Je      FindName
  145.  
  146. FindName2:      Cmp     al, Return              ; stuff all its characters
  147.                 Je      EndName
  148.                 Cmp     al, ' '
  149.                 Je      EndName
  150.                 Cmp     al, 09h
  151.                 Je      EndName
  152.                 Call    StuffIt
  153.                 Lodsb
  154.                 Jmps    FindName2
  155.  
  156. EndName:        StuffChar '='                   ; prepare to set it
  157.                 Cmp     al, Return
  158.                 Je      Done
  159.                                                 ; now parse command line proper
  160.                 Cmp     al, ' '                 ; skip first char, if
  161.                 Je      NextChar                ; blank or tab
  162.                 Cmp     al, 09h
  163.                 Je      NextChar
  164.                 Cmp     al, Return
  165.                 Jne     CheckSpecials
  166. ShowUsage:      Mov     dx, offset Copyright    ; show author's note
  167.                 Mov     ah, 09h
  168.                 Int     21h
  169.                 Mov     dx, offset Usage1       ; show usage hints
  170.                 Mov     ah, 09h
  171.                 Int     21h
  172.                 Mov     dl, [Special]
  173.                 Mov     ah, 02h
  174.                 Int     21h
  175.                 Mov     dx, offset Usage2       ; more usage hints
  176.                 Mov     ah, 09h
  177.                 Int     21h
  178.                 Mov     dl, '$'
  179.                 Mov     ah, 02h
  180.                 Int     21h
  181.                 Mov     dx, offset Usage3       ; more usage hints
  182.                 Mov     ah, 09h
  183.                 Int     21h
  184.                 Mov     ax, 4CFFh               ; termination code
  185.                 Int     21h
  186.  
  187. NextChar:       Lodsb
  188.                 Cmp     al, Return              ; are we done?
  189.                 Jne     CheckSpecials
  190.  
  191. Done:           Mov     si, offset OutLine      ; point to env line
  192.                 Call    env_set                 ; set environment variable
  193.                 Or      [OutLine], 80h          ; set high bit
  194.                 Mov     si, of